package com.burst.reptile.modular.zp.warpper;

import java.time.LocalDateTime;
import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.burst.reptile.common.utils.DateUtil;
import com.burst.reptile.common.utils.NumberUtils;
import com.burst.reptile.common.utils.ToolUtil;
import com.burst.reptile.framework.constant.ConstantFactory;
import com.burst.reptile.framework.web.warpper.BaseControllerWrapper;
import com.burst.reptile.modular.zp.entity.ZpResources;

import cn.hutool.core.util.StrUtil;

public class ZpResourcesWrapper extends BaseControllerWrapper<ZpResources> {

    public ZpResourcesWrapper(Page<ZpResources> page) {
        super(page);
    }
    
    public ZpResourcesWrapper(List<ZpResources> list) {
        super(list);
    }
    
    @Override
    protected void wrapTheMap(ZpResources resources) {
    	String tags = resources.getTags();
		String pictureSet = resources.getPictureSet();
		LocalDateTime updateTime = resources.getUpdateTime();
		String videoUrl = resources.getVideoUrl();
		String posters = resources.getPosters();
		Integer serviceItems = resources.getServiceItems();
		String county = resources.getCounty();
		if(StrUtil.isNotEmpty(tags)) {
			// 文章标签封装
			resources.setTbs(JSONObject.parseArray(tags, String.class));
		}
		if(StrUtil.isNotEmpty(pictureSet)) {
			// 图片数据封装
			resources.setImgs(JSONObject.parseArray(pictureSet, String.class));
		}
		if(ToolUtil.isNotEmpty(updateTime)) {
			// 发布时间封装
			resources.setTime(DateUtil.timeToFormat(updateTime));
		}
		if(ToolUtil.isNotEmpty(videoUrl)) {
			// 视频地址封装
			resources.setVideos(JSONObject.parseArray(videoUrl, String.class));
		}
		if(ToolUtil.isNotEmpty(posters)) {
			// 视频封面地址封装
			resources.setVideoPoster(JSONObject.parseArray(posters, String.class));
		}
		if(ToolUtil.isNotEmpty(posters)) {
			// 视频封面地址封装
			resources.setVideoPoster(JSONObject.parseArray(posters, String.class));
		}
		if(ToolUtil.isNotEmpty(serviceItems)) {
			// 服务项目名称
			resources.setServiceItemsName(ConstantFactory.me().getserviceItemsName(serviceItems));
		}
		// 评论数
		resources.setCommentNum(ConstantFactory.me().getCommentNum(resources.getArticleId()));
		
		if(StrUtil.isNotEmpty(county)) {
			resources.setCountyName(ConstantFactory.me().getAddressName(county));
		}
		// 栏目
		resources.setColumnName(ConstantFactory.me().getColumnName(resources.getColumnId()));
		// 用户信息
		resources.setUser(ConstantFactory.me().getUser(resources.getUserId()));
		
		// 阅读量格式化
		resources.setReadSizeFormat(NumberUtils.amountConversion(resources.getReadSize()));
		// 点赞量格式化
		resources.setVoteSizeFormat(NumberUtils.amountConversion(resources.getVoteSize()));
		// 收藏量格式化
		resources.setCollectSizeFormat(NumberUtils.amountConversion(resources.getCollectSize()));
		
    }

}
